package util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 数据工具类
 * @author Shen
 *
 */

public class DataUtil {
	
	/**
	 * MD5加密
	 * @param src
	 * @return
	 */
	public static String MD5(String src){
				try {
						StringBuffer sb = new StringBuffer();
						char[] chars = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
						byte[] bytes = src.getBytes();
						MessageDigest md;
							md = MessageDigest.getInstance("MD5");
						byte[] targ = md.digest(bytes);
						for(byte b:targ){
							sb.append(chars[(b >> 4) & 0x0F]);
							sb.append(chars[b & 0x0F]);
						}
				
						return sb.toString();
				
				} catch (NoSuchAlgorithmException e) {
					e.printStackTrace();
				}
			return null;				
	}
}
